import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.util.ArrayList; 
import oracle.jdbc.pool.OracleDataSource;

public class houseDetails extends HttpServlet
{
	public static dbapi conn;
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
	{
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		conn = new dbapi();
		conn.connect();
		if(!conn.connected)
		{
			out.println("SQL ERROR CANNOT CONNECT TO DATABASE!<br>");
			out.println(conn.msg + "<br>");
			return;
		}
		home h = conn.getHome(Integer
				.parseInt(request.getParameter("id")));
		if(h==null)
		{
			out.println("Error: null object returned<br>"+conn.msg);
			return;
		}
		out.println("<a href=\"./index.html\">Home</a> "+
			    "<a href=\"getHouses\">House List</a> "+
			    "<a href=\"addAppliance?id="+h.id+"\">Add Appliance</a><br>");
		ArrayList<String> appList = conn.getAppliancesForHouse(h.id);
		out.println(h.address+"<br>");
		out.println(h.city+", ");
		out.println(h.state+"<br>");
		out.println(h.zipcode+"<br><br>");
		out.println("Size: "+Integer.toString(h.sqft)+" sqft<br>");
		out.println("Floors: "+Integer.toString(h.numFloors)+" floors<br>");
		out.println("Bedrooms: "+Integer.toString(h.numBedrooms)+"<br>");
		out.println("Bathrooms: "+Integer.toString(h.numBathrooms)+"<br>");
		out.println("Land Size: "+Integer.toString(h.numFloors)+" acres<br>");
		out.println("Year Made: "+Integer.toString(h.year)+"<br><br>");
		if(appList.size() > 0)
		{
			out.println("Appliances: <br>");
			for(int i=0;i<appList.size();i++)
			{
				out.println(appList.get(i) + "<br>");
			}
		}
	}
}
